package es.ats.codington.web.servlets;

import java.beans.Beans;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.domain.Place;
import es.ats.codington.festival.domain.Visitor;
import es.ats.codington.festival.services.EventService;
import es.ats.codington.festival.services.VisitorService;

/**
 * Servlet implementation class ViewEventServlet
 */
@WebServlet("/ViewMyEventServlet")
public class ViewMyEventServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewMyEventServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	        throws ServletException, IOException {
				
		Object iD = request.getSession().getAttribute("iDVisitor");
	    int id= (Integer) iD;
		EventService es = new EventService();
		ArrayList<Event> myevents = new ArrayList<Event>();
		try{
			
		ArrayList<Integer> myidevents = es.viewMyEvent(id);
		int size = myidevents.size();
		request.setAttribute("size", size);
		
		for (int iter=0; iter<size; iter++){
			Event event = es.viewEvent(myidevents.get(iter));
			myevents.add(event);			
		}
		
		request.setAttribute("evento", myevents);
		RequestDispatcher dispatcher = request
                .getRequestDispatcher("/viewmyevents.jsp"); 
		if (dispatcher != null){  
		      dispatcher.forward(request, response);  
		   }
		
		}catch(Exception ex){
			ex.getMessage();
			
		}
	  }//dGet
		
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	
}
}
	
